Where will you be "hosting" your php page? If you want to view it from your computer without an Internet connect, please be sure you have read the "What is PHP " page in order to setup your computer.
However, if you want to go ahead and get started with PHP , you will need to find a free or commercial PHP web host. There are numerous to list, and many of which can be found on the Other Resources page. For the purpose of this course you can use Zymic - however, I will not discuss how to upload the page to your host... most of that can be found in their own help documentation.
Creating your page
The first thing you will need to do is open up a text editor. If you are on Windows, you should use MS Notepad.
- Take note! There are numerous PHP editors that will help you to create your PHP code in a much more faster and efficient manner however, learning with a simple editor such as notepad will force you to learn the language in its purist form. Some PHP editors can be found on the Other Resources page.
1) Once you open your chosen text editor to edit your PHP, we are going to first begin with the open and close tags:
<?php?>
2) Next, add a comment documenting this day in your PHP history!
<?php// My first PHP page. 10/25/2009?>
Enter anything you want for the comments really, as no one other than you and anyone else you show your PHP source code to will be able to see it. Which brings me to say...
PHP code cannot be seen in the view source of the page. You can ALWAYS see the HTML code, but you will never see the PHP code unless you have access to the actual file.
So... write whatever it is in your comments you want, no one will ever know!
3) Now let us create some variables. We will name our first variable $firstword (or whatever it is you want to name it), and we will assign the text "Hello" to it. We will then create a second variable $secondword and assign the text "world!.
<?php// My first PHP page. 10/25/2009$firstword='Hello';$secondword='World!';?>
4) We will then join these together using double quotes and echo out the text:
<?php// My first PHP page. 10/25/2009$firstword='Hello';$secondword='World!';echo"$firstword$secondword"?>
5) Save this file as "firstpage.php" and upload it to your web host. Then go to the URL where this page is at. For example, if your URL is http://example.com , you would go to http://example.com/firstpage.php .
At this point you should see "Hello World!" !
Congratulations! You have made your first PHP page!
Simple enough, right?
Now.....
Try to display the same text, but using concatenation.
Change the variables to hold different information.
Add new variables and echo them out.
Extra extra! Try putting HTML tags inside of your variables. What happens?
Did you have problems?
Download the completed file located below, and compare it to the one you created.
There is obviously a lot more than can be done with PHP than just displaying information on the page. This is obviously NOT dynamic, because you yourself are adding information into the variables. So how do you learn more?
To go on, view both the resources on the other resources page. Most importantly, dive in, start working with PHP, practice, practice, practice. You will grow, learn, and develop your way to becoming a PHP guru!
First things first!
Where will you be "hosting" your php page? If you want to view it from your computer without an Internet connect, please be sure you have read the "What is PHP " page in order to setup your computer.However, if you want to go ahead and get started with PHP , you will need to find a free or commercial PHP web host. There are numerous to list, and many of which can be found on the Other Resources page. For the purpose of this course you can use Zymic - however, I will not discuss how to upload the page to your host... most of that can be found in their own help documentation.
Creating your page
The first thing you will need to do is open up a text editor. If you are on Windows, you should use MS Notepad.- Take note! There are numerous PHP editors that will help you to create your PHP code in a much more faster and efficient manner however, learning with a simple editor such as notepad will force you to learn the language in its purist form. Some PHP editors can be found on the Other Resources page.
1) Once you open your chosen text editor to edit your PHP, we are going to first begin with the open and close tags:
2) Next, add a comment documenting this day in your PHP history!
Enter anything you want for the comments really, as no one other than you and anyone else you show your PHP source code to will be able to see it. Which brings me to say...
PHP code cannot be seen in the view source of the page. You can ALWAYS see the HTML code, but you will never see the PHP code unless you have access to the actual file.
So... write whatever it is in your comments you want, no one will ever know!
3) Now let us create some variables. We will name our first variable $firstword (or whatever it is you want to name it), and we will assign the text "Hello" to it. We will then create a second variable $secondword and assign the text "world!.
4) We will then join these together using double quotes and echo out the text:
5) Save this file as "firstpage.php" and upload it to your web host. Then go to the URL where this page is at. For example, if your URL is http://example.com , you would go to http://example.com/firstpage.php .
At this point you should see "Hello World!" !
Congratulations! You have made your first PHP page!
Simple enough, right?
Now.....
Did you have problems?
Download the completed file located below, and compare it to the one you created.Where to go from here?
There is obviously a lot more than can be done with PHP than just displaying information on the page. This is obviously NOT dynamic, because you yourself are adding information into the variables. So how do you learn more?
To go on, view both the resources on the other resources page. Most importantly, dive in, start working with PHP, practice, practice, practice. You will grow, learn, and develop your way to becoming a PHP guru!
Good luck =).